﻿Public Class frmWysylkaOferty

    Private mvarChanged As Boolean
    Private mvarCancel As Boolean = False
    Private mvarDbHolder As clsDataBase
    Private mvarOfertaId As Integer
    Private mvarWysylkaOferty As New clsWysylkaOferty
    Private mvarUzytkownik As clsUzytkownik



    Public Sub New(ByVal IdOferty As Integer)

        ' To wywołanie jest wymagane przez projektanta.
        InitializeComponent()

        ' Dodaj inicjację po wywołaniu funkcji InitializeComponent().
        mvarChanged = False
        mvarDbHolder = New clsDataBase(VAR_CONNECTION_PARAMETERS, VAR_ERROR_HANDLER)
        mvarUzytkownik = CType(clsUzytkownik.Instance(), clsUzytkownik)
        mvarOfertaId = IdOferty

    End Sub

    Private Sub Zapisz()
        mvarDbHolder.BeginTrans()
        With mvarWysylkaOferty
            .ID = mvarWysylkaOferty.ID
            .OfertaId = mvarOfertaId
            .PracownikID = mvarUzytkownik.Id
            .DataWysylki = dtpDataWysylki.Value
            .Save(mvarDbHolder, VAR_ERROR_HANDLER)
        End With
        mvarDbHolder.CommitTrans()
        MessageBox.Show("Zapisano do bazy.", "WIREMET")
        mvarChanged = False
        Me.Close()
    End Sub



    Private Sub cmdOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdOK.Click

        If mvarChanged Then
            MessageBox.Show("Nastąpiły zmiany, najpierw zapisz ofertę.", "WIREMET")

        Else
            Zapisz()
        End If

    End Sub

    Private Sub frmWysylkaOferty_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles Me.FormClosed
        mvarDbHolder.Close()
    End Sub


End Class